package com.webex.ta.hydra.gui.wm;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by Cisco WebEx.
 * User: vegaz
 * Date: 2010-10-19
 * Time: 14:37:43
 */
public class SideBarButton extends JToggleButton implements ActionListener {
    private static final Color BACKGROUND = new Color(247, 243, 239);
    private int anchor;
    private String id;

    public SideBarButton(String id, int anchor) {
        this.id = id;
        this.anchor = anchor;
        addActionListener(this);
        init();
    }

    public void setAnchor(int anchor) {
        this.anchor = anchor;
    }

    public int getAnchor() {
        return anchor;
    }

    private void init() {
        setFocusable(false);
        setBackground(BACKGROUND);
        setBorder(BorderFactory.createEmptyBorder(5,5,0,5));
        setText("Project");
        setVisible(true);
        setEnabled(true);
        setSelected(false);
        setRolloverEnabled(true);
        setOpaque(false);
    }

    @Override
    public void updateUI() {
        setUI(SideBarButtonUI.createUI(this));
        Font font = UIManager.getFont("Button.font");
//        if (font.getSize() % 2 ==1) {
            font = font.deriveFont(font.getStyle(), 10);
//        }
        setFont(font);
    }

    public void actionPerformed(ActionEvent e) {
        ToolWindowManager.getInstance().toggleToolWindow(id);
    }
}
